﻿
$(function(){
	//登录
	var cartObj = {
		stockout_gifts : '',
		currentPage_1 : 0,
		scroolTop : 0,
		hg_crnt_page : 1,
		init: function(){
			this.bindCartEvent();
			this.pageInit();
			login.init();
		},
		pageInit : function(){//页面加载初始化 
			//加载列表初始化
			this.loadInit();
			//加载猜你喜欢
			this.loadHot();
			//加载最近浏览
			this.loadViewHis();
			if($('#isLogin').val()){
				cartObj.loadUserCollect();
    		}
		},
		loadInit : function(){
			//加载列表初始化
			var cart = this;
			if($('.promList ul').children().length>0){
				$('.cpTitle .promTit').css('display','inline-block');
			}
    		cart.initJJG();
			cart.resetScroolTop();
    		cart.initArea();
    		cart.initSc();
    		cart.initOrderJJG();
		},
		bindCartEvent: function(){
			var cart = this;
			var proxy_url = "/httpProxyAccess.htm?date="+new Date().getTime();
            //登录
            $('body').delegate('.loginNow', 'click', function(){
            	jQuery.ajax({
        			type : 'post',
        			url : proxy_url,
        			data : {target:domain_passport+'/getUuid.htm'},
        			dataType : 'json',
                	success :function(data){
                		if(data!=null){
                			$('#tt').val(data.uuid);
                			$('#ss').val(data.index);
                		}
                	}
        		});

            	login.loginBoxShow();
            });
            //注册
            $('body').delegate('.regNow', 'click', function(){

            	jQuery.ajax({
        			type : 'post',
        			url : proxy_url,
        			data : {target:domain_passport+'/getUuid.htm'},
        			dataType : 'json',
                	success :function(data){
                		if(data!=null){
                			$('#tt').val(data.uuid);
                			$('#ss').val(data.index);
                		}
                	}
        		});

            	
            	$(".loginBox,.popMask").show();
            	$(".loginTitle  li").first().removeClass("cur").next().addClass("cur");
            	$(".loginMain > div").first().hide().next().show();
            });
          //换购商品弹层
        	$(".hgsp-list ul").each(function(){
        		$(this).find("li").last().css('border-bottom','0px');
        	});
        	$(".shoppingCart").delegate('.hgsp-but','click',function(){
        		$(".hgspBox").hide();
        		$(this).addClass("on").siblings(".hgspBox").show();
        	});
        	$(".shoppingCart").delegate(".hgsp-cancel,.hgsp-close","click",function(){
        		$(this).parents(".hgspBox").hide();
        		$(".hgsp-but").removeClass("on");
        	});
        	$(".shoppingCart").delegate(":text[name=cart_unit_count]","change",function(){
        		cart.countChange($(this));
        	});
        	//底部加价购栏切换
        	$(".shoppingCart").delegate(".inc-t","mouseover",function(){
        		var _this = $(this);
        		$('.increase-tit').find("a").removeClass("itOn");
        		_this.addClass("itOn");
				$('.increase-com').hide();
				var index = $('.increase-tit a').index(_this);
				$('.increase-com').eq(index).show().find("div.inc-list > ul").css("margin-left","0px");
				cart.hg_crnt_page = 1;
        	});
        	//底部加价购栏上一页
        	$(".shoppingCart").delegate("div.inc-prev > span","click",function(){
				var hg_container = $(this).parent().parent().find("div.inc-list > ul");
				cart.hg_crnt_page --;
				if(cart.hg_crnt_page < 1){cart.hg_crnt_page = 1;}
				hg_container.stop().animate({"margin-left":((cart.hg_crnt_page-1) * -879) + "px"});
        	});
        	//底部加价购栏上一页
        	$(".shoppingCart").delegate("div.inc-next > span","click",function(){
        		var hg_container = $(this).parent().parent().find("div.inc-list > ul");
				var hg_pages_count = parseInt(hg_container.find("li").length / 3);
				if(parseInt(hg_container.find("li").length % 3)>0){
					hg_pages_count++;
				}
				cart.hg_crnt_page ++;
				if(cart.hg_crnt_page > hg_pages_count){cart.hg_crnt_page = hg_pages_count;}
				hg_container.stop().animate({"margin-left":((cart.hg_crnt_page-1) * -879) + "px"});
        	});
        	//底部加价购加入购物车
        	$(".shoppingCart").delegate(".inc-int-buy > a","click",function(){
				var _id = $(this).attr('_id');
				var arr = _id.split(',');
				cart.addToCart(arr[0],arr[1],arr[2]);
        	});
        	$(".shoppingCart").delegate('.hgsp-sub','click',function(){
        		var sp_checked = $(this).parent().parent().find(":checked[name='hgsp-check']");
        		if(sp_checked.length == 0){$.showAlert({"title":"提示","content":"请您勾选需要换购的商品", "type":"alarm"});return;}
        		var pack = sp_checked.attr("pack");
        		var goods_id = sp_checked.attr("goods_id");
        		cart.addToCart(pack,1,goods_id);
        		$(this).parents(".hgspBox").hide();
        		$(".hgsp-but").removeClass("on");
        	});
        	
        	/*猜你喜欢切换*/
        	$(".recommenTitle span").hover(function(e) {
        		cart.recomTitClick($(this));
            });
        	$(".recommenList .nextPage").bind('click',function(e) {
        		cart.recommNextPage($(this));
            });
        	$(".recommenList .prevPage").bind('click',function(e) {
        		cart.recommPrevPage($(this));
            });
            //搜索框事件
            $('.shoppingCart').delegate('.empSearch span,.empSearch input', 'click', function(){
        		$(".empSearch input").focus();
        		$(".empSearch span").hide();
            });
            //搜索框事件
            $('.shoppingCart').delegate('.empSearch input', 'blur', function(){
        		if($(".empSearch input").val()==""){
        			$(".empSearch span").show();			
        		}
            });
            //批量删除商品
            $('.shoppingCart').delegate('.deleteGood', 'click', function(){
            	cart.batchDelete();
            	
            });
          //删除商品
            $('.shoppingCart').delegate('.delete', 'click', function(){
        		var _this = $(this);
        		cart.confirmDialog("删除商品","确定从购物车中删除此商品？",function(){
        			cart.doUpdateCart(_this.attr("cart_unit"), 0, "",function(){
            			cart.reloadCart();
            			//九章埋码，删除购物车商品
            			window._JX_INFO = window._JX_INFO || [];
            			if($('#isLogin').val() !='false'){
                    	var userId = cartObj.getCookie("jx_user_id");
        				_JX_INFO.push(["userId",userId]);
            			}
            			var json = [];
            			var  jsonDelCartItem= {"item":"","price":"","quantity":""};
            			var item = _this.next().attr("proid");
        				var price__ = _this.parents('.cTab-tr').find('.cTab-jxPri span').html();
        				var count = _this.parents('.cTab-tr').find('.cTab-amount input').val();
        				jsonDelCartItem.item = _this.next().attr("proid");
        				jsonDelCartItem.price = _this.parents('.cTab-tr').find('.cTab-jxPri span').html();
        				jsonDelCartItem.quantity = _this.parents('.cTab-tr').find('.cTab-amount input').val();
        				json.push(jsonDelCartItem);
        				_JX_INFO.push(["delCartItem",json]);
        				_JX_INFO.push(["go"]);
            			if(_this.attr("cart_unit").indexOf('_')==0||_this.attr("cart_unit").indexOf('QC')==0){//加入删除列表
        					cart.addToDel(_this);
        				}
        			});
        		})
            });
            //清空购物车
            $('.shoppingCart').delegate('.clearCart', 'click', function(){
            	cart.clearCart();
            });
            //减购买数量
            $('.shoppingCart').delegate('.ca-minus', 'click', function(){
            	if(cart.doing)return;
        		var _this = $(this);
        		var inputEle = _this.parent().find(":text[name='cart_unit_count']");
        		var count = parseInt(inputEle.val()) - 1;
        		var cart_unit = _this.attr("cart_unit");
        		if(count<=0){
        			return false;
        		}else{
        			inputEle.val(count < 0 ? 0 : count);
        			cart.doUpdateCart(cart_unit, count, "");
        		}
        	});
            //增加购买数量
            $('.shoppingCart').delegate('.ca-plus', 'click', function(){
            	if(cart.doing)return;
        		var inputEle = $(this).parent().find(":text[name='cart_unit_count']");
        		var count = parseInt(inputEle.val()) + 1;
        		if(count > 99){cart.alertDialog("提示","最多只能购买99件!");return;}
        		var stock = parseInt($(this).attr("stock"));
        		var restriction = parseInt($(this).attr("restriction"));
        		if(restriction >= 0 && count > restriction){cart.alertDialog("提示","对不起，您的购买数量超出了限购。");return;}
        		inputEle.val(count);
        		var cart_unit = $(this).attr("cart_unit");
        		cart.doUpdateCart(cart_unit,count,"");
        	});
            //去提交
            $('.shoppingCart').delegate('.countSubmit', 'click', function(){
            	jQuery.ajax({
        			type : 'post',
        			url : proxy_url,
        			data : {target:domain_passport+'/getUuid.htm'},
        			dataType : 'json',
                	success :function(data){
                		if(data!=null){
                			$('#tt').val(data.uuid);
                			$('#ss').val(data.index);
                		}
                	}
        		});
            	
            	cart.submitOrder($(this));
            });
            //勾选商品
            $('.shoppingCart').delegate(".checkboxs", 'click', function(){
            	var _isMiaoSha = $(this).attr("_isMiaoSha");
            	if(_isMiaoSha !=undefined && _isMiaoSha =='true'){
            		cart.checkMiaoShaGoods($(this).attr("cart_unit"),$(this).attr("checked") == "checked");
            	}else{
            		cart.checkItem($(this).attr("cart_unit"),$(this).attr("checked") == "checked");
            	}
            });
            //全选商品
            $('.shoppingCart').delegate(".checkAll", 'click', function(){
            	var checked = ($(this).attr("checked") == "checked");
        		$(".checkboxs,.checkAll").attr("checked",checked);
        		var skus = new Array();
        		var msSku = "";
        		$(".checkboxs").each(function(){
        			skus.push($(this).attr("cart_unit"));
        			if($(this).attr("cart_unit").indexOf("MS")>-1){
        				msSku = $(this).attr("cart_unit");
        			}
        		});
        		cart.checkItem(skus.join(','),checked);
        		if(msSku !=""){
        			cart.checkMiaoShaGoods(msSku,checked);
        		}
            });
            //收藏商品
            $('.shoppingCart').delegate(".sc", 'click', function(){
            	var cart = this;
            	if($('#isLogin').val()=='false'){
            		login.loginBoxShow();
            		return false;
        		}
        		var event = $(this);
        		saves(event.attr("proId"),function(data){
        			if(data.code==0){
        				event.parent().append('<span class="ysc" proid='+event.attr("proId")+'>已收藏</span>');
        				event.remove();
        			}
        		},'cart');
        	});
            //加入购物车
            $('body').delegate("a[name='add_to_cart_btn']", 'click', function(){
            	var isnotsale = $(this).attr("isnotsale");
            	if(isnotsale=='true'){
            		var goodName = $(this).parent().prevAll('.goodName').children().html();
            		$.showAlert({"title":"提示","content":"商品["+goodName+"]是非卖品", "type":"alarm"});
            		return false;
            	}
            	var count = $(this).attr("_count");
            	var src = $(this).attr("_src");
            	var pack = $(this).attr("pack");
            	if(pack==undefined){
            		pack = '';
            	}
            	var removeDel = true;
        		if (count == null || count == 'undefined') {
        			count = 1;
        			removeDel = false;
        		}
        		cart.addToCart(pack,count,$(this).attr("_proid"),removeDel,src);
            });
            //鼠标滚动结算栏悬浮
        	$(window).bind("scroll",function(){
        		var divTop=$(window).scrollTop()+$(window).height()-47;
        		if(divTop<cart.scroolTop){
        			$(".moneyDetail").addClass("moneyDetailFixed");
        		}else{
        		  $(".moneyDetail").removeClass("moneyDetailFixed");
        		}
        	});
        	$('.shoppingCart').delegate(".promTit", 'mouseover', function(){
        		cart.promTitClick($(this));
        	});
        	$('.shoppingCart').delegate(".cpClose", 'click', function(){
        		$(".cpTitle span,.goodDetail").removeClass("on");
        		$(".cpContent .cpList").hide();
        		$(this).hide();
        		$(this).parents(".CoupAndProm").css('height','68px');
        		$('#cpState').val(0);
        		cart.resetScroolTop();
        	});
        	$('.shoppingCart').delegate(".hgBtn", 'click', function(){
        		$(".hgspBox").hide();
        		$(this).addClass("on").siblings(".hgspBox").show();
        	});
			$('.shoppingCart').delegate(".hgspSure", 'click', function(){
        		var sp_checked = $(this).parent().parent().find(":checked[name='hgspCheck']");
        		if(sp_checked.length == 0){$.showAlert({"title":"提示","content":"请您勾选需要换购的商品", "type":"alarm"});return;}
        		var goods_id = sp_checked.attr("goods_id");
        		cart.addToCart("DDJJG",1,goods_id);
        		$(this).parents(".hgspBox").hide();
        		$(".promotionHg .hgBtn").removeClass("on");
        	});
			$('.shoppingCart').delegate(".hgspBox .hgspCancel,.hgspBox .hgspClose", 'click', function(){
        		$(this).parents(".hgspBox").hide();
        		$(".promotionHg .hgBtn").removeClass("on");
        	});
		},
		initOrderJJG : function(){
        	var cart = this;
			//选择换购商品
        	var sp_checkboxs=$('.promotionHg .hgspBox').find(":checkbox[name='hgspCheck'][_disabled='false']");
    		var hgsp_box = $(this);
    		sp_checkboxs.change(function(){
    			if($(this).attr("checked") == "checked"){
    				sp_checkboxs.attr("disabled",true);
    				$(this).parent().parent().css({"background":"#fffaf1"});
    				$(this).attr("disabled",false);
    			}else{
    				$('.promotionHg .hgspBox').find("li").css({"background":"#FFFFFF"});
    				sp_checkboxs.attr("disabled",false);
    			}
    		});
		},
		initJJG:function(){
			var jjg_goods_container = $("#jjg_goods_container");
			jjg_goods_container.empty();
			if(typeof(jjg_goods)!="undefined"){
				if(jjg_goods.length > 0){
					var jjg_goods_tit = $("<div class='increase-tit'></div>");
					jjg_goods_container.append(jjg_goods_tit);
					for(var i = 0;i<jjg_goods.length;i++){
						jjg_goods_tit.append("<a href='#' class='inc-t'>加"+jjg_goods[i][0].price+"元即可换购</a>")
						var jjg_goods_list = $("<div class='increase-com' style='display: none;'></div>");
						jjg_goods_container.append(jjg_goods_list);
						jjg_goods_list.append("<div class='increase-name'><span class='in-icon'><em>换购</em></span><span class='in-text'>仅需加<b>"+jjg_goods[i][0].price+"</b>元，即可换购任一商品，购完为止 </span></div>");
						jjg_goods_list.append("<div class='increase'><div class='inc-prev'><span class='cartIcon'></span></div><div class='inc-list'><ul></ul></div><div class='inc-next'><span class='cartIcon'></span></div><div class='clear'></div></div>");
						var ul = jjg_goods_list.find("div.inc-list > ul");
						for(var j =0; j<jjg_goods[i].length;j++){
						ul.append("<li><div class='inc-pic'><a target='_blank' href='"+jjg_goods[i][j].href+"'><img src='"+jjg_goods[i][j].img+"'></a></div><div class='inc-intro'><p class='inc-int-name'><a target='_blank' href='"+jjg_goods[i][j].href+"'>"+jjg_goods[i][j].name+"</a></p><p class='inc-int-pri'><b>￥"+jjg_goods[i][j].price+"</b><del>￥"+jjg_goods[i][j].jxprice+"</del></p><p class='inc-int-buy'><a href='javascript:void(0);' _id='"+jjg_goods[i][j].goods_pack+",1,"+jjg_goods[i][j].goods_id+"' class='cartIcon'></a></p></div><div class='clear'></div></li>");
						}
					}
					jjg_goods_container.find("div.increase-tit > a").eq(0).addClass("itOn");
					$(".increase-com").eq(0).show();
				}
				//选择换购商品
	        	$('.hgspBox').each(function(){
	        		var sp_checkboxs=$(this).find(":checkbox[name='hgsp-check']");
	        		var hgsp_box = $(this);
	        		sp_checkboxs.change(function(){
	        			if($(this).attr("checked") == "checked"){
	        				sp_checkboxs.attr("disabled",true);
	        				$(this).parent().parent().css({"background":"#fffaf1"});
	        				$(this).attr("disabled",false);
	        			}else{
	        				hgsp_box.find("li").css({"background":"#FFFFFF"});
	        				sp_checkboxs.attr("disabled",false);
	        			}
	        		});
	        	});
			}
		},
        initSc : function(){
        	var allProIds = new Array();
        	$(".sc").each(function(){
        		allProIds.push($(this).attr("proId"));
        	});
        	if(allProIds.length > 0){
        		jQuery.post("/siftUserCollectedProIds.htm",{"proIds":allProIds.join()},function(data){
        			if(data && data.result!="" && data.result!="undefind"){
        				var tmp = ","+data.result+",";
        				$(".sc").each(function(){
        					if(tmp.indexOf(","+$(this).attr("proId")+",")!=-1){
        						$(this).parent().append('<span class="ysc" proid='+$(this).attr("proId")+'>已收藏</span>');
        						$(this).remove();
        					}
        				});
        			}
        		});
        	}
        },
        resetScroolTop : function (){
        	var cart = this;
        	if(!$(".step_offset").offset()){
        		return;
        	}
        	cart.scroolTop = $(".step_offset").offset().top;
        	var divTop=$(window).scrollTop()+$(window).height()-47;
        	if(divTop<cart.scroolTop){
        		$(".moneyDetail").addClass("moneyDetailFixed");
        	}else{
        		$(".moneyDetail").removeClass("moneyDetailFixed");
        	}
        },
        addToCart :function(pack,count,goods,removeDel,src){
        	var cart = this;
        	jQuery.post("/addToCart.htm",{"pack":pack,"count":count,"goods":goods,"src":src},function(data){
        		if(data.status==1){
        			cart.reloadCart();
        			if(removeDel){
        				$(".tableDefault a[_proid="+goods+"]").parents("tr").remove();
            			if($(".tableDefault tr").length==0){
            				$(".delTableBox,.delTabTitle").hide();
            			}
        			}
        		}else{
        			if(data.stack.indexOf("快递停发") >-1){
        				var alertstrtpm = data.stack;
        				var eint = alertstrtpm.indexOf("]");
        				alertstr=alertstrtpm.substring(eint+1,alertstrtpm.length);
        				var startTime = alertstr.split(",")[0].split("-")[0];
        				$(".start").html(startTime);
        				$(".end").html(endTime);
        				$.showAlert({"title":"提示","content":'该地区于'+startTime+'至'+endTime+'快递停发，您可以继续下单，我们将会在年后第一时间给您发货!', "type":"confirm","cancelShow":true
        					,callback:function() {
        					cartObj.setCookie("knowStopDelivery","true",1);
        				}});
        			}else{
        				$.showAlert({"title":"提示","content":data.stack, "type":"alarm"});
        			}
        		}
        	});
        },
        countChange:function(_this){
        	var cart = this;
    		var cart_unit = _this.attr("cart_unit");
    		var defaultCount = parseInt(cart_unit_counts[cart_unit]);
    		if(!/^\d+$/.test(_this.val())){ _this.val(defaultCount); return; }

    		var count = parseInt(_this.val());
    		var stock = parseInt(_this.attr("stock"));
    		var restriction = parseInt(_this.attr("restriction"));
    		
    		if(count > 99){$.showAlert({"title":"提示","content":"最多只能购买99件!", "type":"alarm"});_this.val(defaultCount);return;}
    		if(count <= 0){
    			$.showAlert({"title":"删除商品","content":"是否从购物车删除这件商品?", "type":"confirm","cancelShow":true,
    				callback:function() {
    					cart.doUpdateCart(cart_unit, 0, "", "");
    					if(cart_unit.indexOf('_')==0||cart_unit.indexOf('QC')==0){//加入删除列表
    						cart.addToDel(_this.parents('.cTab-tr').find('.delete'),defaultCount);
    					}
    			},'cancelCallback':function(){
    				_this.val(defaultCount);return;
    			}});
    		}else if(restriction >= 0 && count > restriction){/**alert("这件商品限购"+restriction+"件。")*/
    			$.showAlert({"title":"提示","content":"对不起，您的购买数量超出了限购。", "type":"alarm"});_this.val(defaultCount);return;
    		}else{
    			cart.doUpdateCart(cart_unit,count,"");
    		}
        },
        doUpdateCart:function(cart_unit,count,packgoods,callback){
        	var cart = this;
        	cart.doing = true;
        	jQuery.post("/updateCart.htm",{"sku":cart_unit,"count":count,"packgoods":packgoods},function(data){
        		if(data.status==1){
        			if(callback){
        				callback();
        			}else{
            			cart.reloadCart();
        			}
        		}else{
        			if(data.stack){
        				cart.alertDialog("提示",data.stack);
        			}else{
        				alert("服务器繁忙，请稍后重试!");
        			}
        		}
        	});
        },
        batchDelete:function(){
        	var cart = this;
        	var selected_item = $(":checked[name='cart_item']");
    		if(selected_item.length==0){
    			$.showAlert({"title":"提示","content":"请先选择要删除的商品", "type":"alarm"});
    		}else{
    			$.showAlert({"title":"删除商品","content":"确定从购物车中删除这些商品？", "type":"confirm","cancelShow":true,
    				callback:function() {
    					var skuArray = new Array();
    					var _thisArray = new Array();
    					selected_item.each(function(){
    						skuArray.push($(this).attr("cart_unit"));
    						_thisArray.push($(this).parents('.cTab-tr').find('.delete'));
    					});
    					jQuery.post("/removeFromCart.htm",{"sku":skuArray.join()},function(data){
    						//九章埋码，批量删除购物车商品
    						window._JX_INFO = window._JX_INFO || [];
		            		if($('#isLogin').val() !='false'){
		            			var userId = cartObj.getCookie("jx_user_id");
		            			_JX_INFO.push(["userId",userId]);
	            			}
                			var json = [];
    						if(data.status==1){
    							for(var i=0 ;i< skuArray.length;i++){
    								var jsonDelCartItem = new Object();
        							jsonDelCartItem.item = _thisArray[i].next().attr("proid");
        	        				jsonDelCartItem.price = _thisArray[i].parents('.cTab-tr').find('.cTab-jxPri span').html();
        	        				jsonDelCartItem.quantity = _thisArray[i].parents('.cTab-tr').find('.cTab-amount input').val();
        	        				json.push(jsonDelCartItem);
        	        				if(skuArray[i].indexOf('_')==0||skuArray[i].indexOf('QC')==0){
    									cart.addToDel(_thisArray[i]);
    								}
    							}
    							_JX_INFO.push(["delCartItem",json]);
    							_JX_INFO.push(["go"]);
    							cart.reloadCart();
    						}else{
    							if(data.stack){
    								alert(data.stack);
    							}else{
    								alert("服务器繁忙，请稍后重试!");
    							}
    						}
    					});
    			}});
    		}
        },
        clearCart : function(){
        	var cart = this;
        	cart.confirmDialog("清空购物车","确定清空购物车吗？",function(){
        		jQuery.post("/clearCart.htm",{},function(data){
					if(data.status==1){
                        //九章埋码，清空购物车商品
                        var json = [];
                        $.each($(".cTab-tr  "), function(index, item) {
                            var jsonDelCartItem = new Object();
                            jsonDelCartItem.item = $(item).find(".opeBox a").eq(1).attr("proid");
                            jsonDelCartItem.price = $(item).find(".cTab-jxPri span").text();
                            jsonDelCartItem.quantity = $(item).find(".cAmount-add .ctxt").val();
                            json.push(jsonDelCartItem);
                        });
                        window._JX_INFO = window._JX_INFO || [];
						if($('#isLogin').val() !='false'){
							var userId = cartObj.getCookie("jx_user_id");
							_JX_INFO.push(["userId",userId]);
						}
                        _JX_INFO.push(["delCartItem",json]);
						_JX_INFO.push(["go"]);

						cart.reloadCart();
					}else{
						if(data.stack){
							alert(data.stack);
						}else{
							alert("服务器繁忙，请稍后重试!");
						}
					}
				});
        	})
    	},
        checkItem:function(cart_unit,checked){
        	var cart = this;
    		jQuery.post("/toggleCartItem.htm",{"sku":cart_unit,"checked":checked},function(data){
    			if(data.status==1){
    				cart.reloadCart();
    			}else{
    				if(data.stack){
    					cart.alertDialog("提示",data.stack);
    				}else{
    					alert("服务器繁忙，请稍后重试!");
    				}
    			}
    		});
        },
        checkMiaoShaGoods:function(cart_unit,checked){
        	var cart = this;
	        jQuery.post("/toggleMiaoShaGoods.htm",{"sku":cart_unit,"checked":checked},function(data){
				if(data.status==1){
					cart.reloadCart();
				}else{
					if(data.stack){
						cart.alertDialog("提示",data.stack);
					}else{
						alert("服务器繁忙，请稍后重试!");
					}
				}
			});
        },
        alertDialog : function(title,content){
        	$.showAlert({"title":title,"content":content, "type":"alarm"});
        },
        confirmDialog : function(title,content,callback){
        	$.showAlert({"title":title,"content":content, "type":"confirm","cancelShow":true,
    			callback:callback
    		});
        },
        reloadCart : function(){
        	var cart = this;
        	$("#jjg_goods_container").html("");
        	$("#cart_container").load("/loadMyCart.htm",{},function(){
        		cart.loadInit();
        		cart.doing = false;
        	});
        },
        addToDel:function(_this,count){
    		if(_this.parents('.comOff').length>0){
    			return;
    		}
    		var tab_tr = _this.parents('.cTab-tr');
    		var t = $(".tableDefault tr").length % 2==1 ? ' class=" even"' : '';
    		var proid = _this.next().attr("proid");
    		if(proid==''||proid=='undefined'){
    			return false;
    		}
    		if(count==null||count==''){
    			count = tab_tr.find('.cTab-amount input').val();
    		}
    		var pack = '';
    		if(_this.attr('cart_unit').indexOf('QC')==0){
    			pack = 'QC';
    		}
    		$('#DEL_'+proid).remove();
    		var arr = new Array();
        	arr.push('<tr'+t+' id="DEL_'+proid+'"><td class="goodTbodyName">');
        	arr.push('<div class="goodName">'+tab_tr.find('.cn-Con p').html()+'</div></td>');
        	arr.push('<td class="goodTbodyPrice">￥<span>'+tab_tr.find('.cTab-jxPri span').html()+'</span></td><td class="goodTbodyNum">'+count+'</td>');
        	arr.push('<td class="goodTbodyOperate"><div class="operateBox"><a _count="'+count);
        	arr.push('" _proid="'+proid+'" href="#" pack="'+pack+'" name="add_to_cart_btn">重新购买</a>');
        	var sc = tab_tr.find('.opeBox > :last').html();
        	if(sc=='收藏'){
            	arr.push('<a href="javascript:void(0);" class="sc" proid="'+proid+'">收藏</a>');
        	}else{
            	arr.push('<span class="ysc" proid="'+proid+'">已收藏</span>');
        	}
        	arr.push('</div></td></tr>');
        	
    		$(".tableDefault tbody").append(arr.join(''));
    		$(".delTabTitle span").html($(".tableDefault tr").length+'件');
    		$(".delTableBox,.delTabTitle").show();
    	},
        initArea: function(){
            region.initCitySelector();
        },
        submitOrder:function(submit_btn){
        	var cart = this;
        	if($('.checkboxs:checked').length == 0){
    			cart.alertDialog("提示","请先勾选需要结算的商品");
    		}else if($('#isLogin').val()=='false'){
        		login.toSubmit=true;
        		login.loginBoxShow();
    		}else{
    			cart.stockout_gifts=$('#stockout_gifts').val();
        		if(cart.stockout_gifts != ""){
        			cart.confirmDialog("提示","赠品已赠完，是否继续？",function(){
    					cart.toSubmit(submit_btn);
        			});
        		}else{
        			cart.toSubmit(submit_btn);
        		}
    		}
        },
        toSubmit :function(submit_btn){
        	window._JX_INFO = window._JX_INFO || [];
        	_JX_INFO.push(["eventId","submitOrderBtn"]);
        	_JX_INFO.push(["clientId",10000]);
        	_JX_INFO.push(["go"]);
    		submit_btn.hide();
    		$(".sett-submit").show();
    		$.ajax({
    			type: "post",
    		    url: "/verifyCart.htm",
                dataType: "json",
                success: function (data) {
                	if(data.status==1){
                		window.location.href = domain_cart+'/order/confirm.htm?stockoutGifts='+cartObj.stockout_gifts+'&'+ Math.random();
        			}else if(data.status == -1){
        				cartObj.reloadCart();
        			}else{
        				submit_btn.show();
        				$(".sett-submit").hide();
        				$.showAlert({"title":"提示","content":data.stack, "type":"alarm"});
        			}
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                	alert(errorThrown);
                }
            });
    	},
    	loadHot : function(){
    	    if(cartObj.getCookie("ABTest")=='-1'){
    	    	this.loadMyHot();
    	    }
    	    if(window.loadRecommend){
    	    	loadRecommend('cart');
    	    	loadRecommend('cartNewPro');
    	    	setTimeout(cartObj.loadMyHot,2000);
    	    }
    	},
    	loadMyHot:function(){
    		if($('#mycart_tophotGoods').html()!=''){return false;}
    		$.ajax({
    			type: "post",
    		    url: "/loadHotGoods.htm",
                dataType: "json",
                success: function (data) {
                	var hotGoods = data.loadHotGoods;
                	if(hotGoods){
                		var htmlA = new Array;
                		htmlA.push('<ul class="clearfix">');
                		var srcs = ["4331","4332","4333","4334","4335","4336","4337","4338","4339","4340","4341","4342","4343","4344","4345","4346","4347","4348","4349","4350"];
                		var proIds=[];
                		for(var i=0;i<hotGoods.length;i++){
    		            	proIds.push(hotGoods[i].ID);
    		            	var link = domain_detail+"/goods-"+hotGoods[i].ID+".html";
        					var imgarray = hotGoods[i].listImagePath.split('.');
        	    			var imgUrl = domain_img10+imgarray[0]+'2.'+imgarray[1];
    		            	htmlA.push('<li><div class="imgBox"><a title="'+hotGoods[i].name+'" target="_blank" href="'+link+'?src='+srcs[i]+'" ><img src="'+imgUrl+'" width="160" height="160"/></a><p class="Tag Tag_1"></p></div><div class="goodInfo"><p class="goodName"><a title="'+hotGoods[i].name+'" target="_blank" href="'+link+'?src='+srcs[i]+'">'+hotGoods[i].name+'</a></p><p class="goodPrice"><b><span _data="price" _proid="'+hotGoods[i].ID+'"  id="cartpri_'+hotGoods[i].ID+'">￥</span></b><p class="goodBuy"><a class="cartIcon" href="#" _proid="'+hotGoods[i].ID+'" name="add_to_cart_btn"><i class="cartIcon"></i><span>加入购物车</span></a></p></div></li>');
    		            }
    		            htmlA.push('</ul>');
    					$("#mycart_tophotGoods").html(htmlA.join(''));
    		            getProductActPrice(proIds.join(','),'handleCartPrice');
    					$(".recommenBox").css('height','307px');
    					$(".recommenList").css('height','270px');
                	}
	            },
	            error: function (XMLHttpRequest, textStatus, errorThrown) {
//	            	alert(errorThrown);
	            }
            });
    	},
    	recomTitClick : function(_this){
    		var cart = this;
    		var $parents=_this.parents(".recommenBox");
			$(".recommenBox").css('height','307px');
			$(".recommenList").css('height','270px');
    		var index=$(".recommenTitle span").index(_this);
    		$(".recommenTitle span").removeClass("on");
    		$(".recommenTitle span").eq(index).addClass("on");
    		$(".recommenBox .recommenListNot").hide();
    		$parents.find(".recommenList").hide();
    		var _recommenListON = $parents.find(".recommenList").eq(index);
            if(_recommenListON.find(".clearfix").find("li").length>0){
            	_recommenListON.show();
    			$(".recommenBox").css('height','307px');
    			$(".recommenList").css('height','270px');
            	cart.currentPage_1=0;
        		$(".recommenCon ul").css("margin-left","0");
        		$(".recommenList .prevPage").removeClass('on')
        		if(_recommenListON.find(".clearfix").find("li").length>5){
            		$(".recommenList .nextPage").addClass('on')
        		}else{
            		$(".recommenList .nextPage").removeClass('on')
        		}
            }else{
            	if(index!=0){
	    			$(".recommenBox").css('height','307px');
	    			$(".recommenList").css('height','270px');
	            	$(".recommenBox .recommenListNot").show();
            	}else{
            		$(".recommenBox").css('height','57px');
					$(".recommenList").css('height','20px');
	            	_recommenListON.show();
            	}
            }
    	},
    	recommNextPage:function(_this){
    		var cart = this;
    		var $this = _this.parent();
    		var pages=parseInt($this.find("li").length/5);
			var remainNum=parseInt($this.find("li").length%5);
            var $bigUl = $this.find("ul").eq(0);
            cart.currentPage_1++;
    		function noMove(s){
    			if(!s.is(":animated")){
    				return true;
    			}
    			else{
    				return false;
    			};
    		};
    		if(cart.currentPage_1 < pages ){
    			$bigUl.stop().animate({
    				"marginLeft": (cart.currentPage_1 * (-980)) + "px"
    			},500); 
    		}else if(cart.currentPage_1 > pages){
    			cart.currentPage_1--;
    			return false;
    		}else if(cart.currentPage_1==pages){
    			if(remainNum==0){
    				cart.currentPage_1--;
    			}else{
        			var oNumber=5-remainNum;
        			$bigUl.stop().animate({
        			"marginLeft": (cart.currentPage_1 * (-980))+(oNumber*196)+ "px"
        			},500);
    			}
    		}
    		if(cart.currentPage_1 >0){
    			$(".recommenList .prevPage").addClass("on");
    		}
    		if(remainNum>0){pages++};
    		if(cart.currentPage_1 == pages-1){
    			_this.removeClass("on");
    		}
    	},
    	recommPrevPage:function(_this){
    		var cart = this;
    		var $this = _this.parent();
            var $bigUl = $this.find("ul").eq(0);
    		var pages=parseInt($this.find("li").length/5);
    		var remainNum=parseInt($this.find("li").length%5);
    		if(remainNum>0){
    			pages++;
    		}
    		if(cart.currentPage_1==0){
    			return false;
    		}
    		cart.currentPage_1--;
    		$bigUl.stop().animate({"marginLeft": (cart.currentPage_1 * (-980)) + "px"},500); 
    		if(cart.currentPage_1==0){
    			_this.removeClass("on");			
    		} 
    		if(pages > 0){
    			$(".recommenList .nextPage").addClass("on");
    		}
    	},
    	promTitClick:function(_this){
    		var cart = this;
    		var tIndex = $(".cpTitle span").index(_this);
    		var $liNum = $(".cpContent .cpList").eq(tIndex);
    		var tState = $liNum.css("display");
    		if(tState=="none"){
    			_this.addClass("on").siblings().removeClass("on");
    			$liNum.show().siblings().hide();
    			$(".cpClose").show();
    			$(".goodDetail").addClass("on");
    			_this.parents(".CoupAndProm").css('height','auto');			
    			var liLength=$liNum.find("li").length;
    			if(liLength>=3){
					$liNum.find("ul").css('height','90px');
    			}
    			if(tIndex==0){
    				$('#cpState').val(1);
    			}else{
    				$('#cpState').val(2);
    			}
    		}else{
    			_this.removeClass("on");
    			$liNum.hide();
    			$(".cpClose").hide();
    			$(".goodDetail").removeClass("on");
    			_this.parents(".CoupAndProm").css('height','68px');
    			$('#cpState').val(0);
    		}
			cart.resetScroolTop();
    	},
    	loadUserCollect:function(){//加载用户收藏
    		$.getJSON('/getUserCollect.htm',function(data){
    	    	if(data.state=='1'){
    	    		var arr = new Array();
    	    		var proIds = [];
    	    		$.each(data.userCollect,function(i,n){
    	    			if(n.img_s){
        	    			var imgarray = n.img_s.split(".");
        	    			var imgUrl = imgarray[0]+'2.'+imgarray[1];
        	    			proIds.push(n.id);
        	        		arr.push('<li><div class="imgBox">');
        	        		arr.push('<a title="'+n.name+'" href="'+domain_detail+'/goods-'+n.id+'.html" target="_blank"><img width="160" height="160" src="'+domain_img10+imgUrl+'"></a>');
        	        		arr.push('<p class="Tag Tag_1"></p></div><div class="goodInfo"><p class="goodName"><a title="'+n.name+'" href="'+domain_detail+'/goods-'+n.id+'.html" target="_blank">'+n.name+'</a></p>');
        	        		arr.push('<p class="goodPrice"><b>￥<span id="coll_'+n.id+'" _data="price" _proid="'+n.id+'"></span></b></p>');
        	        		arr.push('<p class="goodBuy"><a class="cartIcon" href="#" _proid="'+n.id+'" isnotsale="'+n.isNotForSale+'" name="add_to_cart_btn"><i class="cartIcon"></i><span>加入购物车</span></a></p>');
        	        		arr.push('</div></li>');
    	    			}
    	    		});
    	    		$("#ul_userCollect").append(arr.join(''));
    	    		getProductActPrice(proIds.join(','),function(priceData){
			            for (var proId in priceData) {
			                var proPrices = priceData[proId];
			                $("#coll_"+proId).text(proPrices.np.toFixed(2));
			            }
		            });
    	    	}
    	    });
    	},
    	loadViewHis:function(){//加载最近浏览
    		$.getJSON('/getViewHis.htm',function(data){
    	    	if(data.state=='1'){
    	    		var arr = new Array();
    	    		var proIds = [];
    	    		$.each(data.hisGoods,function(i,n){
    	    			if(n.img_s){
        	    			var imgarray = n.img_s.split(".");
        	    			proIds.push(n.id);
        	    			var imgUrl = imgarray[0]+'2.'+imgarray[1];
        	        		arr.push('<li><div class="imgBox">');
        	        		arr.push('<a title="'+n.name+'" href="'+domain_detail+'/goods-'+n.id+'.html" target="_blank"><img width="160" height="160" src="'+domain_img10+imgUrl+'"></a>');
        	        		arr.push('<p class="Tag Tag_1"></p></div><div class="goodInfo"><p class="goodName"><a title="'+n.name+'" href="'+domain_detail+'/goods-'+n.id+'.html" target="_blank">'+n.name+'</a></p>');
        	        		arr.push('<p class="goodPrice"><b>￥<span id="his_'+n.id+'" _data="price" _proid="'+n.id+'"></span></b></p>');
        	        		arr.push('<p class="goodBuy"><a class="cartIcon" href="#" _proid="'+n.id+'" isnotsale="'+n.isNotForSale+'" name="add_to_cart_btn"><i class="cartIcon"></i><span>加入购物车</span></a></p>');
        	        		arr.push('</div></li>');
    	    			}
    	    		});
    	    		$("#ul_viewhis").append(arr.join(''));
    	    		getProductActPrice(proIds.join(','),function(priceData){
			            for (var proId in priceData) {
			                var proPrices = priceData[proId];
			                $("#his_"+proId).text(proPrices.np.toFixed(2));
			            }
		            });
    	    	}
    	    });
    	},
    	setCookie:function(c_name, value, expiredays) {
    		var exdate = new Date();
    		exdate.setDate(exdate.getDate() + expiredays);
    		document.cookie = c_name + "=" + escape(value)
    				+ ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
    				+ ";path=/;domain=jiuxian.com"
    	},
    	getCookie:function(objName) {
    		var arrStr = document.cookie.split("; ");
    		for ( var i = 0; i < arrStr.length; i++) {
    			var temp = arrStr[i].split("=");
    			if (temp[0] == objName) {
    				return unescape(temp[1])
    			}
    		}
    		return ""
    	}
	};

	var login = {
			susCallback : null,
			uname : cartObj.getCookie("jx_uname"),
			init :function(){
				var lg = this;
				$(".loginBox .loginTitle .close").click(function(e) {
					lg.loginClose();
					regClose();
				});
				$('#userName').bind('focus',function(){
					$(this).siblings('.filter').find('p').hide();
					$(this).siblings('.mistakeTip').hide();
					$(this).removeClass('on').addClass('focus');
					$(this).siblings('.filter').find(".status").hide();
					if($(this).val()==""){
						$(this).siblings('.filter').find(".markdel").hide();
					}else{
						$(this).siblings('.filter').find(".markdel").show();
					}
				});
				$('#userName').bind('blur',function(){
					var flag1=/\S{1,20}/g;
					var flag2=/[a-zA-Z0-9_-]/g; 
					var flag3 = /^[^\s]{4,50}$/;
					var uname = jQuery.trim($(this).val());
					if( uname ==''){
						$(this).siblings('.filter').find('p').show();
						$(this).parent().addClass('wrong');
						$(this).siblings('.mistakeTip').text("请输入用户名/邮箱/手机号").show();
						$(this).addClass('on').removeClass('focus');;
						$('#userName').val("");
						$(this).siblings('.filter').find(".status").show();
						$(this).siblings('.filter').find(".markdel").hide();
					}else{
						$(this).siblings('.filter').find('p').hide();
						$(this).parent().removeClass('wrong');
						$(this).siblings('.mistakeTip').hide();
						$(this).removeClass('on focus');
						$(this).siblings('.filter').find(".status").hide();
					}
				});
				$('#userName,#password').bind('keyup',function(){
					if($(this).val()==''){
						$(this).parent().find('.markdel').hide();
					}else{	
						$(this).parent().find('.markdel').show();
					}
				});
				$('#userName,#password').bind('change',function(){
					if($(this).val()==''){
						$(this).parent().find('.markdel').hide();
					}else{	
						$(this).parent().find('.markdel').show();
						$(this).parent().find('.tip').hide();
						$(this).siblings('.mistakeTip').hide();
						$(this).removeClass('on');
						$(this).parent().removeClass('wrong');
					}
				});
				$('.loginItem .markdel').bind('click',function(){
					$(this).parent().find('.markdel').hide();
					$(this).parent().next().val('').focus();
				});
				$('.loginItem .filter p').bind('click',function(){
					$(this).parent().next().focus();
				});
				$('#password').bind('focus',function(){
					$(this).siblings('.filter').find('p').hide();
					$(this).siblings('.mistakeTip').hide();
					$(this).removeClass('on').addClass('focus');
					$(this).siblings('.filter').find(".status").hide();
					if($(this).val()==""){
						$(this).siblings('.filter').find(".markdel").hide();
					}else{
						$(this).siblings('.filter').find(".markdel").show();
					}
				});
				$('#password').bind('blur',function(){
					if($(this).val()=='')
					{
						$(this).siblings('.filter').find('p').show();
						$(this).parent().addClass('wrong');
						$(this).siblings('.mistakeTip').text("请输入密码").show();
						$(this).addClass('on').removeClass('focus');
						$(this).siblings('.filter').find(".status").show();
						$(this).siblings('.filter').find(".markdel").hide();
					}else{
						$(this).siblings('.filter').find('p').hide();
						$(this).parent().removeClass('wrong');
						$(this).siblings('.mistakeTip').hide();
						$(this).removeClass('on focus');
						$(this).siblings('.filter').find(".status").hide();
					}
				});
				$('#verification').bind('focus',function(){
					$(this).siblings('.filter').find('p').hide();
					$(this).siblings('.mistakeTip').hide();
					$(this).removeClass('on').addClass('focus');
				})
				$('#verification').bind('blur',function(){
					if(jQuery.trim($(this).val())=='')
					{
						$(this).siblings('.filter').find('p').show();
						$(this).addClass('on').removeClass('focus');
						$(this).siblings('.mistakeTip').text('请输入验证码').show();
						$(this).val('');
					}else{
						$(this).siblings('.filter').find('p').hide();
						$(this).parent().removeClass('wrong');
						$(this).removeClass('on focus');
						$(this).siblings('.mistakeTip').text('').hide();
					}
				})
				$('#_captchaImage >i').bind('click',function(){
					jQuery("#captchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
				});
				$("#loginBtn").bind("click",function(){			
					if (!CookieEnable()){
						alert( "对不起，您的浏览器的Cookie功能被禁用，请开启后刷新重试" );
						return false;
					}else{
						var checkStatus = true;
						$(".loginItem .form01").each(function(){
							var value = $.trim($(this).val());
							if(value=="")
							{
								$(this).siblings(".filter").find(".tip").show();
								$(this).siblings(".mistakeTip").show();
								$(this).siblings(".filter").find('.status').show();
								$(this).parent().addClass('wrong');
								$(this).addClass("on");
								$(this).val("");
								checkStatu = false;
							}
						});
						var unameVaild = $("#userName").parent().hasClass('wrong');
						var pwdVaild = $("#password").parent().hasClass('wrong');
						if(unameVaild || pwdVaild){
							return false;
						}else {//提交表单
							//给密码赋值
							var pwd = $("#password").val();
							var modulus = $("#modulus").val();
							var exponent = $("#exponent").val();
							var publicKey = RSAUtils.getKeyPair(exponent, '',modulus);
				        	$('#pwd').val(RSAUtils.encryptedString(publicKey, pwd));
							//判断是否有验证码，如果有验证，先验证验证码，之后提交
							if($("#validcaptcha").css('display')!='none'){
								var verification = $("#verification").val();
								if(verification==''){
					        		$("#verification").addClass('on');
					        		$("#verification").siblings('.mistakeTip').text('请输入验证码').show();
					        		$("#verification").val('');
				        			jQuery("#captchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
									return false;
								}
							}
							$('#um').val(encodeURI($('#userName').val()));
				        	$('#remember').val($('#loginAuto').attr('checked')=="checked" ? "yes" : "no");
				        	$("#isToSubmit").val('');
				        	
				        	if(login.toSubmit){
				        		
				        		$("#isToSubmit").val("A");
							}
				        	var loginForm = $("#loginform");
				        	if($("#fromUrl").size() == 0){
					        	loginForm.append("<input id='fromUrl' name='from' type='hidden' value='"+domain_cart+"'/>");
				        	}
							var act_request_url = domain_passprot+"/newlogin.htm";
							$("#loginBtn").val('正在登录...');
							jQuery.ajax({
								url: act_request_url,
				    		 	data:loginForm.serialize(),
								dataType:"jsonp",
								jsonpCallback:"callbackSc",
								context: this,
								success: function(data) {
									lg.loginSuc(data);
								}
							});
						}
						return false;
					}
				});
			},
			loginSuc : function(data){
				if (data != null && data.action_status == 1) {
					cartObj.setCookie("jx_uname", $('#userName').val(), 7);
					if($("#isToSubmit").val()!=''){
	            		window.location.href = domain_cart+'/order/confirm.htm?'+ Math.random();
	            		return ;
					}
					cartObj.reloadCart();
					cartObj.loadUserCollect();
					$("#isLogin").val(true);
					$(".loginBox .loginTitle .close").click();
					login.profile();
					return;
				} else if (data != null && data.action_status == 888) {
					
					cartObj.setCookie("jx_uname", $('#userName').val(), 7);
					location.href = data.action_msgs[0];
				} else if (data != null && data.action_status == 5) {
					cartObj.setCookie("jx_uname", $('#userName').val(), 7);
					window.location.href = "http://shop.jiuxian.com";
				} else {
					$("#loginBtn").val('登  录');
					jQuery("#captchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
				}
				if(data!=null&&(data.action_status==2||data.action_status==3)){
					var _this = $("#userName");
					if(data.action_status==3){
						_this = $("#password");
					}
					var errormsg =  data.action_msgs[0];
					_this.parent().addClass('wrong');
					_this.siblings('.mistakeTip').text(errormsg);
					_this.siblings('.mistakeTip').show();
					_this.siblings('.filter').find(".status").show();
					_this.siblings('.filter').find(".markdel").hide();
					_this.addClass('on');
					if(data.isCaptcha=="yes"){
						//登陆错误次数超过3次，验证码出来
						$("#validcaptcha").show();
					}
				}else if(data!=null&&data.action_status==4){
					var errormsg = data.action_msgs[0];
					$("#validcaptcha").show();
					$("#verification").addClass('on');
					$("#verification").siblings('.mistakeTip').text(errormsg).show();
					return false;
				}else if(data.code=='999'){
					$("#password").parent().addClass('wrong');
					$("#password").siblings('.mistakeTip').text('非法字符，请重新输入');
					$("#password").siblings('.mistakeTip').show();
					$("#password").addClass('on');
				}else{
					var msg = data.action_msgs[0];
					$("#validcaptcha").show();
					$("#verification").parent().addClass('wrong');
					$("#verification").siblings('.mistakeTip').text(msg).show();
					$("#verification").addClass('on'); 
				}
			},
			loginBoxShow : function(){
	        	if(this.uname!=''&&$('#userName').val()==''){
	        		$('#userName').val(this.uname);
	        	}
	        	if($('#userName').val()!=''){
	        		$('.userNameItem .markdel').show();
	        		$("#userName").siblings('.filter').find('p').hide();
	        	}else{
	        		$('.userNameItem .markdel').hide();
	        	}
	        	if($('#password').val()!=''){
	        		$('.passWordItem .markdel').show();
	        		$("#password").siblings('.filter').find('p').hide();
	        	}else{
	        		$('.passWordItem .markdel').hide();
	        	}
	        	if(login.toSubmit){
	        		$(".cooperateWay > a").each(function(i,n){
	        			var _this = $(this);
	        			_this.attr("href",_this.attr("_href")+"?from="+domain_cart+"/order/confirm.htm");
	        		});
	        	}else{
	        		$(".cooperateWay > a").each(function(i,n){
	        			var _this = $(this);
	        			_this.attr("href",_this.attr("_href")+"?from="+domain_cart);
	        		});
	        	}
	            $(".loginBox,.popMask").show();
	            $(".loginTitle  li").first().addClass("cur").next().removeClass("cur");
            	$(".loginMain > div").first().show().next().hide();
	            
	        	jQuery("#captchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
	        },
	        loginClose : function(){
		        $(".loginBox .form01").val("").removeClass('on');
		        $(".loginBox .filter p").show();
		        $(".loginBox .mistakeTip").hide();
		        $(".loginBox .status").hide();
				$('#loginAuto').removeAttr('checked');
		        $(".loginBox,.popMask").hide();
		        $(".loginTab a").first().addClass('on').next().removeClass('on');
				login.toSubmit = false;
			},
			profile:function() {
				var searchUrl = domain_public+"/selectSearchDefaultKey.htm?t="+new Date().getTime();
				jQuery.post("/addJXCenterCookie.htm",
							{ 
								"target":searchUrl,
								"name":"searchBoxDefaultKey"
							},
							function(d){
								if(d==undefined) return;
								var data=eval("("+ d.defaultSearchKey+")");
								// profile callback
								profileback(d);
							},		
							"json");
			}
	};
	
	//登录注册切换
	
	$(".loginTitle li").bind('click',function(){
		var index = $(this).index();
		$(this).addClass("cur").siblings().removeClass("cur");
		$(".logTab").eq(index).show().siblings().hide();
	});
	

	$(".loginTab a").bind('click',function(){
		var index = $(this).index();
		$(this).addClass("on").siblings().removeClass("on");
		$(".regTab").eq(index).show().siblings().hide();
	});
		
	$(".regInputBox .regInput").each(function() {
        var thisVal = $(this).val();
		if(thisVal != ""){
			$(this).siblings("p").hide();
		};
    });
	
	$(".loginMain .regInput").focus(function(){
		
		$(this).siblings("p").hide();
		$(this).siblings(".poiTrue").show();
		$(this).siblings(".poiFalse").hide();
		$(this).siblings(".regPointIcon").removeClass("regTrue").hide();
		if($(this).hasClass("yzCode"))
		{
			$(this).parent().removeClass("on").addClass("bdOn");
			
		}else{
			$(this).removeClass("on").addClass("bdOn");
		}
	});
	
	var time =59;
	var i=null;
	function getTimer(){
		time--;
		if(time==0){
			clearInterval(i);
			$(".qjwSubmit1").show();
			$(".qjwSubmit2").hide();
			time=59;
		}
		$(".qjwSubmit2 em").text(time);
	}
	var etime =59;
	var ei=null;
	function eGetTimer(){
		etime--;
		if(etime==0){
			clearInterval(ei);
			$(".qjwSubmit3").show();
			$(".qjwSubmit4").hide();
			etime=59;
		}
		$(".qjwSubmit4 em").text(etime);
	}

	//注册
	function regClose(){
        $(".regInputBox .regInput").val("").removeClass('on');
		$(".regInputBox .poiFalse").hide();
		$(".regInputBox .tip").show();
		$(".regInputBox .regPointIcon").removeClass("regTrue").hide();
        $(".loginBox,.popMask").hide();
        $(".loginTab a").first().addClass('on').next().removeClass('on');
        $(".regTab").eq(0).show().siblings().hide();
        $(".regAgrInput").attr("checked","checked");
        $(".regAgrInput2").attr("checked","checked");
        $(".regAgreePoint").hide();
        clearInterval(i);
        $(".qjwSubmit1").show();
		$(".qjwSubmit2").hide();
		time=59;
		$(".qjwSubmit2 em").text(time);
		clearInterval(ei);
        $(".qjwSubmit3").show();
		$(".qjwSubmit4").hide();
		time=59;
		$(".qjwSubmit4 em").text(etime);
	}
		
	//注册协议
	$(".regAgrInput").click(function(e) {
		var flag=$(this).attr("checked");
		if(flag=="checked")
		{
			$(this).attr("checked","checked");
			$(this).parents(".regAgreeBox").siblings(".regAgreePoint").hide();
		}
		else
		{
			$(this).attr("checked",false);
			$(this).parents(".regAgreeBox").siblings(".regAgreePoint").show();
		}	
		
    });
	$(".regAgrInput2").click(function(e) {
		var flag=$(this).attr("checked");
		if(flag=="checked")
		{
			$(this).attr("checked","checked");
			$(this).parents(".regAgreeBox").siblings(".regAgreePoint").hide();
		}
		else
		{
			$(this).attr("checked",false);
			$(this).parents(".regAgreeBox").siblings(".regAgreePoint").show();
		}	
		
    });
	
	function showError($obj,msg){
		$obj.parent().addClass('wrong').removeClass("right");
		$obj.siblings(".poiTrue").hide();
		$obj.siblings(".poiFalse").text(msg).show();
		$obj.siblings(".regPointIcon").removeClass("regTrue").show();
		$obj.addClass('on');
	}
	
	//用户名邮箱注册开始
	var canEamilSubmit = true;
	
	$("#submit").click(function(e) {
		
		var flag=$(".regAgrInput2").attr("checked");
		if(flag!="checked"){
			$("#email_regAgreePoint").show();
			return false;	
		}else{
			$("#email_regAgreePoint").hide();
			var unameVaild = checkName($("#eUsername"),1);
			var pwdVaild = checkPwd($("#ePassword"));
			var phoneVaild = checkPhone($("#ePhoneNum"),1);
			if(pwdVaild){
				//给密码赋值
    			var pwd = $("#ePassword").val();
    			var modulus = $("#modulus").val();
    			var exponent = $("#exponent").val();
    			var publicKey = RSAUtils.getKeyPair(exponent, '',modulus);
            	$('#ePasswordHi').val(RSAUtils.encryptedString(publicKey, pwd));
			}
			var repwdVaild = checkRePwd($("#eRePassword"),$("#ePassword"));
			if(repwdVaild){
				
				//给密码赋值
    			var pwd = $("#eRePassword").val();
    			var modulus = $("#modulus").val();
    			var exponent = $("#exponent").val();
    			var publicKey = RSAUtils.getKeyPair(exponent, '',modulus);
            	$('#eRePasswordHi').val(RSAUtils.encryptedString(publicKey, pwd));
			}
			var checkCodeVaild = checkCode1($("#eVerification"));
			var checkCodeVaild1 = checkCode($("#ePhoneverification"));
			$('#eUsernameHi').val(encodeURI($('#eUsername').val()));
			$('#ePhoneNumHi').val(encodeURI($('#ePhoneNum').val()));
			if(unameVaild && pwdVaild && repwdVaild && phoneVaild && checkCodeVaild && checkCodeVaild1 && canEamilSubmit){
				canEamilSubmit = false;
				var register_request_url = domain_passprot+"/newregister.htm";
				jQuery.ajax({
					type:'post',
					url: register_request_url,
	    		 	data:$("#registform").serialize(),
					dataType:"jsonp",
					jsonpCallback:"callbackSc",
					context: this,
					success: function(data) {
						if(data!=null&&data.action_status==0){
							var errormsg =  data.action_msgs[0];
							$("#eVerification").parent().removeClass('bdOn').removeClass('on');
							$("#eVerification").siblings(".poiTrue").hide();
							$("#eVerification").siblings(".poiFalse").text(errormsg).show();
							$("#eVerification").siblings(".regPointIcon").removeClass("regTrue").show();
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==12){//邮箱
							$('.regWrap').hide();
							$('.regSuccess').show();
							
							//设置记录用户名cookie
							setCookie("jx_uname",$("#eUsername").val(),7);
							//注册成功
							var sTime = 5;
							var tCount = setInterval(function(){
								sTime--;
								if(sTime>0){
									$(".regSuccessCon span").text(sTime+"秒");
								}else{
									$(".loginBox,.popMask").hide();
									window.location.href = "http://cart.jiuxian.com";
								}
								
							},1000)

						}else if(data!=null&&data.action_status==13){//账号注册
							$('.regWrap').hide();
							$('.regSuccess').show();
							
							//设置记录用户名cookie
							setCookie("jx_uname",$("#eUsername").val(),7);
							//注册成功
							var sTime = 5;
							var tCount = setInterval(function(){
								sTime--;
								if(sTime>0){
									$(".regSuccessCon span").text(sTime+"秒");
								}else{
									$(".loginBox,.popMask").hide();
									window.location.href = "http://cart.jiuxian.com";
								}
								
							},1000)
						}else if(data!=null&&data.action_status==999){
							$("#password").addClass("on");
							$("#password").siblings(".poiTrue").hide();
							$("#password").siblings(".poiFalse").text("非法字符，请重新输入").show();
							$("#password").siblings(".regPointIcon").removeClass("regTrue").show();
							canEamilSubmit = true;
							//return false;
						}
						
						if(data!=null&&data.action_status==2){
							var msg = data.action_msgs[0];
							showError($("#eUsername"),msg);
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==3){
							var msg = data.action_msgs[0];
							showError($("#ePassword"),msg);
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==4){
							var msg = data.action_msgs[0];
							showError($("#eRePassword"),msg);
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==5){
							var msg = data.action_msgs[0];
							showError($("#ePhoneNum"),msg);
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==6){
							var msg = data.action_msgs[0];
							showError($("#ePhoneverification"),msg);
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==7){
							var msg = data.action_msgs[0];
							$("#eVerification").parent().addClass('on').addClass('wrong').removeClass("right");
							$("#eVerification").siblings(".poiTrue").hide();
							$("#eVerification").siblings(".poiFalse").text(msg).show();
							$("#eVerification").siblings(".regPointIcon").removeClass("regTrue").show();
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null&&data.action_status==12){//邮箱						
							$('.regWrap').hide();
							$('.regSuccess').show();
							
							//设置记录用户名cookie
							setCookie("jx_uname",$("#eUsername").val(),7);
							//注册成功
							var sTime = 5;
							var tCount = setInterval(function(){
								sTime--;
								if(sTime>0){
									$(".regSuccessCon span").text(sTime+"秒");
								}else{
									$(".loginBox,.popMask").hide();
									window.location.href = "http://cart.jiuxian.com";
								}
								
							},1000)
						}else if(data!=null&&data.action_status==13){//账号注册
							$('.regWrap').hide();
							$('.regSuccess').show();
							
							//设置记录用户名cookie
							setCookie("jx_uname",$("#eUsername").val(),7);
							//注册成功
							var sTime = 5;
							var tCount = setInterval(function(){
								sTime--;
								if(sTime>0){
									$(".regSuccessCon span").text(sTime+"秒");
								}else{
									$(".loginBox,.popMask").hide();
									window.location.href = "http://cart.jiuxian.com";
								}
								
							},1000)
						}else if(data!=null&&data.action_status==999){
							$("#eVerification").addClass("on");
							$("#eVerification").siblings(".poiTrue").hide();
							$("#eVerification").siblings(".poiFalse").text(data.action_msgs[0]).show();
							$("#eVerification").siblings(".regPointIcon").removeClass("regTrue").show();
							canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}else if(data!=null){
						    var msg = data.action_msgs[0];
						    $("#eVerification").removeClass("on");
						    $("#eVerification").siblings(".poiTrue").hide();
						    $("#eVerification").siblings(".poiFalse").show();
						    $("#eVerification").siblings(".regPoint").text(msg);
						    $("#eVerification").siblings(".regPointIcon").removeClass("regTrue").show();
						    canEamilSubmit = true;
							jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
						}
					}
					
				});
			
			}
		}

    });
	
	//用户名邮箱注册结束
	
	//手机号注册提交开始
	
	var canSubmit = true;
	$("#phoneSubmit").click(function(e) {
		var flag=$(".regAgrInput").attr("checked");
		if(flag!="checked"){
			$("#phone_regAgreePoint").show();
			return false;	
		}else{
			
			$("#phone_regAgreePoint").hide();
			var phoneVaild = checkPhone($("#phoneNum"),1);
			var pwdVaild = checkPwd($("#phonePwd"));
			if(pwdVaild){
				//给密码赋值
    			var pwd = $("#phonePwd").val();
    			var modulus = $("#modulus").val();
    			var exponent = $("#exponent").val();
    			var publicKey = RSAUtils.getKeyPair(exponent, '',modulus);
            	$('#phonePwdHi').val(RSAUtils.encryptedString(publicKey, pwd));
			}
			var repwdVaild = checkRePwd($("#phoneRePwd"),$("#phonePwd"));
			if(repwdVaild){
//				给密码赋值
    			var pwd = $("#phoneRePwd").val();
    			var modulus = $("#modulus").val();
    			var exponent = $("#exponent").val();
    			var publicKey = RSAUtils.getKeyPair(exponent, '',modulus);
            	$('#phoneRePwdHi').val(RSAUtils.encryptedString(publicKey, pwd));
			}
			var checkCodeVaild = checkCode($("#phoneverification"));
			var checkCodeVaild1 = checkCode1($("#phone_verification"));
			$('#phoneNumHi').val(encodeURI($('#phoneNum').val()));
			if(phoneVaild && pwdVaild && repwdVaild && checkCodeVaild && checkCodeVaild1 && canSubmit){
				var register_request_url = domain_passprot+"/newregister.htm";
				canSubmit = false;
				//ajax提交表单
				jQuery.ajax({
					type:'post',
					url: register_request_url,
	    		 	data:$("#phoneRegform").serialize(),
					dataType:"jsonp",
					jsonpCallback:"callbackSc",
					context: this,
					success: function(data) {
						if(data!=null&&data.action_status==2){
    						var msg = data.action_msgs[0];
    						showError($("#phoneNum"),msg);
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==3){
    						var msg = data.action_msgs[0];
    						showError($("#phonePwd"),msg);
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==4){
    						var msg = data.action_msgs[0];
    						showError($("#phoneRePwd"),msg);
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==5){
    						var msg = data.action_msgs[0];
    						showError($("#phoneNum"),msg);
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==6){
    						var msg = data.action_msgs[0];
    						showError($("#phoneverification"),msg);
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==7){
    						var msg = data.action_msgs[0];
    						$("#phone_verification").parent().addClass('on').addClass('wrong').removeClass("right");
							$("#phone_verification").siblings(".poiTrue").hide();
							$("#phone_verification").siblings(".poiFalse").text(msg).show();
							$("#phone_verification").siblings(".regPointIcon").removeClass("regTrue").show();
    						canSubmit = true;
    						jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}else if(data!=null&&data.action_status==11){//手机
    						$('.regWrap').hide();
							$('.regSuccess').show();
							
    						//设置记录用户名cookie
    						setCookie("jx_uname",$("#phoneNum").val(),7);
    					
    						var sTime = 5;
							var tCount = setInterval(function(){
								sTime--;
								if(sTime>0){
									$(".regSuccessCon span").text(sTime+"秒");
								}else{
									$(".loginBox,.popMask").hide();
									window.location.href = "http://cart.jiuxian.com";
								}
							},1000)
						}else if(data!=null){
						    var msg = data.action_msgs[0];
						    $("#phone_verification").removeClass("on");
						    $("#phone_verification").siblings(".poiTrue").hide();
						    $("#phone_verification").siblings(".poiFalse").show();
						    $("#phone_verification").siblings(".regPoint").text(msg);
							canSubmit = true;
							jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
    					}
					}
				});
			}
		}
	});
	
	//手机号注册提交结束
	
	var region = {
			returnArrya : function(n, p) {
				for ( var j = 0; j < K.kind_region[n].length; j++) {
					if (K.kind_region[n][j][0] == p) {
						return K.kind_region[n][j]
					}
				}
			},
			addList : function(p, n) {
				$(".areaList").eq(n).find("ul").empty();
				for ( var j = 0; j < p.length; j++) {
					var op = "<li><a href='#' pid='" + p[j][0] + "'>" + p[j][1] + "</a></li>";
					if (p[j][0] != 33 && p[j][0] != 34 && p[j][0] != 35) {
						$(".areaList").eq(n).find("ul").append(op)
					}
				}
			},
			outTextTerritory:function(text, index, pid) {
				$(".selectedBox a").eq(index).html('<em>' + text + '</em><i></i>').attr(
						"pid", pid)
			},
			bind1:function() {
				$(".areaList").eq(1).find("a").unbind("click");
				$(".areaList").eq(1).find("a").bind("click", function(e) {
					region.outTextTerritory($(this).text(), 1, $(this).attr("pid"));
					$(".selectedBox a").eq(2).html('<em>请选择县/区</em><i class="cartIcon"></i>');
					$(".areaList").hide().eq(2).show();
					$(".selectedBox a").removeClass("on").eq(2).addClass("on");
					region.addList(K.kind_region[$(this).attr("pid")], 2);
					region.bind2();
					region.bindH5();
				});
			},
			bind2:function() {
				$(".areaList").eq(2).find("a").unbind("click");
				$(".areaList").eq(2).find("a").bind("click",function(e) {
						region.outTextTerritory($(this).text(), 2, $(this).attr("pid"));
						$(".areaDetail").hide();
						$(".selectArea").removeClass("on");
						$(".selectedBox a").removeClass("on");
						for ( var i = 0; i < $(".selectArea b").length; i++) {
							$(".selectArea b").eq(i).text($(".selectedBox a").eq(i).text()).attr("pid",$(".selectedBox a").eq(i).attr("pid"));
						}
						cartObj.setCookie("user_province", $(".selectedBox a").eq(0).attr("pid")+ "_"+ $(".selectedBox a").eq(1).attr("pid")+ "_"+ $(".selectedBox a").eq(2).attr("pid"), 12);							$(".ajax_deli_city").text($(".selectedBox a").eq(0).text());
						cartObj.reloadCart();
					});
			},
			bindH5:function() {
				$(".selectedBox a").unbind("click");
				$(".selectedBox a").bind("click", function(e) {
					var ind = $(".selectedBox a").index($(this));
					$(".selectedBox a").removeClass("on");
					$(this).addClass("on");
					$(".areaList").hide();
					$(".areaList").eq(ind).show()
				});
			},
			initCitySelector:function(){
				$(".selectArea").click(function(e) {
					$(".selectArea").addClass("on");
					$(".areaDetail").show();
					$(".selectedBox a").removeClass("on");
					$(".areaList").hide();
					e.stopPropagation();
				});
				$("body").click(function(e) {
					$(".areaDetail").hide();
					$(".selectArea").removeClass("on");
				});
				$(".areaList,.areaDetail").click(function(e) {
					e.stopPropagation();
				});
				var userArray=cartObj.getCookie("user_province");
				userArray = userArray.split("_");
				if(userArray[0] != ""){
					$(".cart_city b").text(region.returnArrya(1,userArray[0])[1]);
				}else{
					$(".cart_city b").text("北京");
					userArray[0] = 2;
				}
				// 初始化送货地址
				if (userArray[0] != "") {
					var sa1 = region.returnArrya(1, userArray[0]);
					$(".selectArea b").eq(0).text(sa1[1]).attr("pid", sa1[0]);
					$(".selectedBox a").eq(0).html('<em>' + sa1[1] + '</em><i class="cartIcon"></i>').attr("pid", sa1[0]);
					if (userArray[1] != "" && userArray[1] != undefined) {
						var sa = region.returnArrya(userArray[0], userArray[1]);
						if(sa!=undefined && sa != ""){
							$(".selectArea b").eq(1).text(sa[1]).attr("pid", sa[0]);
							$(".selectedBox a").eq(1).html('<em>' + sa[1] + '</em><i class="cartIcon"></i>').attr("pid", sa[0]);
							if (userArray[2] != "" && userArray[2] != undefined) {
								var sa = region.returnArrya(userArray[1], userArray[2]);
								if(sa!=undefined && sa != ""){
									$(".selectArea b").eq(2).text(sa[1]).attr("pid", sa[0]);
									$(".selectedBox a").eq(2).html('<em>' + sa[1] + '</em><i class="cartIcon"></i>').attr("pid", sa[0]);	
								}
								
							}
						}
						
					}
				} else {
					$(".selectArea b").eq(0).text("北京").attr("pid", 2);
					$(".selectedBox a").eq(0).html('<em>北京</em><i class="cartIcon"></i>').attr("pid", 2);
					userArray[0] = 2;
				}
				if (!userArray[1]) {
					$(".selectedBox a").eq(1).html('<em>请选择市</em><i class="cartIcon"></i>');
					$(".selectedBox a").eq(2).html('<em>请选择县/区</em><i class="cartIcon"></i>');
				}
				region.addList(K.kind_region[1], 0);
				region.addList(K.kind_region[userArray[0]], 1);
				region.bindH5();
				$(".selectedBox a").eq(2).unbind("click");
				if (userArray[1] != undefined && userArray[1] != "" && userArray[1] != "undefined") {
					region.addList(K.kind_region[userArray[0]], 1);
					region.bindH5();
					$(".selectedBox a").eq(2).unbind("click");
				}
				if (userArray[2] != undefined && userArray[2] != ""
						&& userArray[2] != "undefined" && userArray[1] != undefined
						&& userArray[1] != "" && userArray[1] != "undefined") {
					region.addList(K.kind_region[userArray[1]], 2);
					region.bindH5();
				}
				region.bind1();
				region.bind2();
				$(".areaList").eq(0).find("a").bind("click", function(e) {
					region.outTextTerritory($(this).text(), 0, $(this).attr("pid"));
					$(".selectedBox a").eq(1).html('<em>请选择市</em><i class="cartIcon"></i>');
					$(".selectedBox a").eq(2).html('<em>请选择县/区</em><i class="cartIcon"></i>');
					$(".areaList").hide().eq(1).show();
					$(".selectedBox a").removeClass("on").eq(1).addClass("on");
					region.addList(K.kind_region[$(this).attr("pid")], 1);
					$(".selectedBox a").eq(2).unbind("click");
					region.bind1();
				})
			}
		};
	cartObj.init();
	
	//用户名邮箱注册失去焦点验证开始
	
	$("#eUsername").bind("blur",function() {
		checkName($(this),0);
	});
	
	$("#ePassword").bind('blur',function(){
		checkPwd($(this));
	});
	$("#eRePassword").bind('blur',function(){
		checkRePwd($(this),$("#ePassword"));
	});
	
	$('#eVerification').bind('blur',function(){
		checkCode1($(this));
	});
	
	$('#ePhoneNum').bind('blur',function(){
		checkPhone($(this));
	});
	
	$('#ePhoneverification').bind('blur',function(){
		checkCode($(this));
	});
	//用户名邮箱注册失去焦点验证结束

	//注册获取新的验证码
	$('#regYzCode').bind('click',function(){
		jQuery("#reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
	});
	$('#phone_regYzCode').bind('click',function(){
		jQuery("#phone_reCaptchaImage").attr("src", domain_public+"/public/captchaimg.htm?timestamp" + (new Date()).valueOf());
	});

	//手机号注册失去焦点验证开始
	$('#phoneNum').bind('blur',function(){
		checkPhone($(this));
	});
	
	$('#phoneverification').bind('blur',function(){
		checkCode($(this));
	});
	$("#phonePwd").bind('blur',function(){
		checkPwd($(this));
	});
	
	$("#phoneRePwd").bind('blur',function(){
		checkRePwd($(this),$("#phonePwd"));
	});
	
	$('#phone_verification').bind('blur',function(){
		checkCode1($(this));
	});
	//手机号注册失去焦点验证结束
	
	//获取手机验证码(手机注册)
	$(".qjwSubmit1").click(function() {
	
		var proxy_url = "/httpProxyAccess.htm?date="+new Date().getTime();
		var value=$.trim($("#phoneNum").val());
		if(value=="")
		{
			 $(this).parents(".regAccInfor").prev().find("input").addClass("on").removeClass("bdOn");
			 $(this).parents(".regAccInfor").prev().find(".poiTrue").hide();
			 $(this).parents(".regAccInfor").prev().find(".poiFalse").text("请输入手机号码").show();
			 $(this).parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
			 $(this).parents(".regAccInfor").prev().find(".tip").show();
			 return false;
		}
		else
		{
			var flag=/^(13|14|15|18|17)[0-9]{9}$/; 
			
			if(!flag.test(value))
			{
				 $(this).parents(".regAccInfor").prev().find("input").addClass("on").removeClass("bdOn");
				 $(this).parents(".regAccInfor").prev().find(".poiTrue").hide();
				 $(this).parents(".regAccInfor").prev().find(".poiFalse").text("请输入正确的手机号码");
				 $(this).parents(".regAccInfor").prev().find(".poiFalse").show();
				 $(this).parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();	
			}
			else
			{
				
				//ajax验证
        		jQuery.ajax({	
            		type:'post',
                	url:proxy_url,
                	data:{target:domain_passport+"/newcheck_uname.htm",param:value},
                	dataType:'json',
                	success:function(data){
                		if(data!=null&&data.status=='n'){
        					var info = data.info;
        					$(".qjwSubmit1").parents(".regAccInfor").prev().find("input").addClass("on");
							$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiTrue").hide();
							$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiFalse").text(info);
							$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiFalse").show();
							$(".qjwSubmit1").parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
        					return false;
            			}else{
 
            				var t = $("#tt").val();
            				var s = $("#ss").val();
            				$(this).parents(".regAccInfor").prev().find("input").removeClass("on");
							//ajax发送请求,向后台获取手机验证码
							var phone = jQuery.trim($("#phoneNum").val());
	  						var contentType = "register";
	  						var j_captcha = $("#phone_verification").val().trim(); // 图形验证码
	  					   jQuery.ajax({
	  							 type:'post',
	  							 url:proxy_url,
	  							 data:{target:domain_passport+"/send_msm.htm", param:value,phone:phone,j_captcha:j_captcha,contentType:contentType,t:t,s:s},
	  							 dataType:'json',
	  							 success:function(data){
	  								if(data!=null&&data.action_status==1){
										$(".qjwSubmit1").hide();
										$(".qjwSubmit2").show();
										i=setInterval(getTimer,1000);
								}else{
									var errMsg = data.action_msgs[0];
									$(".qjwSubmit1").parents(".regAccInfor").prev().find("input").addClass("on");
                					$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiTrue").hide();
                					$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiFalse").text(errMsg);
                					$(".qjwSubmit1").parents(".regAccInfor").prev().find(".poiFalse").show();
                					$(".qjwSubmit1").parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
								}
	  							 }
	  					    });
            			}
                	}
        		});
			}
		}
    });
	
	//获取手机验证码(邮箱注册)
	$(".qjwSubmit3").click(function() {
	
		var proxy_url = "/httpProxyAccess.htm?date="+new Date().getTime();
		var value=$.trim($("#ePhoneNum").val());
		if(value=="")
		{
			 $(this).parents(".regAccInfor").prev().find("input").addClass("on").removeClass("bdOn");
			 $(this).parents(".regAccInfor").prev().find(".poiTrue").hide();
			 $(this).parents(".regAccInfor").prev().find(".poiFalse").text("请输入手机号码").show();
			 $(this).parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
			 $(this).parents(".regAccInfor").prev().find(".tip").show();
			 return false;
		}
		else
		{
			var flag=/^(13|14|15|18|17)[0-9]{9}$/; 
			
			if(!flag.test(value))
			{
				 $(this).parents(".regAccInfor").prev().find("input").addClass("on").removeClass("bdOn");
				 $(this).parents(".regAccInfor").prev().find(".poiTrue").hide();
				 $(this).parents(".regAccInfor").prev().find(".poiFalse").text("请输入正确的手机号码");
				 $(this).parents(".regAccInfor").prev().find(".poiFalse").show();
				 $(this).parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();	
			}
			else
			{
				
				//ajax验证
        		jQuery.ajax({	
            		type:'post',
                	url:proxy_url,
                	data:{target:domain_passport+"/newcheck_uname.htm",param:value},
                	dataType:'json',
                	success:function(data){
                		if(data!=null&&data.status=='n'){
        					var info = data.info;
        					$(".qjwSubmit3").parents(".regAccInfor").prev().find("input").addClass("on");
							$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiTrue").hide();
							$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiFalse").text(info);
							$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiFalse").show();
							$(".qjwSubmit3").parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
        					return false;
            			}else{
 
            				var t = $("#tt").val();
            				var s = $("#ss").val();
            				$(this).parents(".regAccInfor").prev().find("input").removeClass("on");
							//ajax发送请求,向后台获取手机验证码
							var phone = jQuery.trim($("#ePhoneNum").val());
	  						var contentType = "register";
	  						var j_captcha = $("#eVerification").val().trim(); // 图形验证码
	  					   jQuery.ajax({
	  							 type:'post',
	  							 url:proxy_url,
	  							 data:{target:domain_passport+"/send_msm.htm", param:value,phone:phone,j_captcha:j_captcha,contentType:contentType,t:t,s:s},
	  							 dataType:'json',
	  							 success:function(data){
	  								if(data!=null&&data.action_status==1){
										$(".qjwSubmit3").hide();
										$(".qjwSubmit4").show();
										ei=setInterval(eGetTimer,1000);
								}else{
									var errMsg = data.action_msgs[0];
									$(".qjwSubmit3").parents(".regAccInfor").prev().find("input").addClass("on");
                					$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiTrue").hide();
                					$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiFalse").text(errMsg);
                					$(".qjwSubmit3").parents(".regAccInfor").prev().find(".poiFalse").show();
                					$(".qjwSubmit3").parents(".regAccInfor").prev().find(".regPointIcon").removeClass("regTrue").show();
								}
	  							 }
	  					    });
            			}
                	}
        		});
			}
		}
    });

	//验证用户名
	
	function checkName($obj,type){
			var flag1 = /^([a-zA-Z0-9_\.]+)@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;//验证邮箱
			var flag2 = /^([\u2E80-\u9FFF]{1}|[a-zA-Z-_]{1})+[\u2E80-\u9FFFa-zA-Z0-9_-]{3,19}$/;
			var username = jQuery.trim($obj.val());
			if(username==''){
				$obj.addClass("on").removeClass("bdOn");
				$obj.siblings(".poiTrue").hide();
				$obj.siblings(".poiFalse").css("width","auto");
				$obj.siblings(".poiFalse").text("请输入邮箱或用户名").show();
				$obj.siblings(".regPointIcon").removeClass("regTrue").show();
				$('#username').val('');
				$obj.siblings(".tip").show();
				return false;
			}else{
				//屏蔽非法词
				var lowerUsername=username.toLowerCase();
				if(lowerUsername.indexOf("酒帝网")==-1 && lowerUsername.indexOf("官方")==-1 && 
				   lowerUsername.indexOf("客服")==-1 && lowerUsername.indexOf("jiuxian")==-1 && 
				   lowerUsername.indexOf("酒帝")==-1 && lowerUsername.indexOf("jiuxianwang")==-1){
					
					if(username.indexOf("@")>-1){//邮箱
						return checkEamil($obj,flag1,type);
					}else{//用户名注册
						return checkAccuout($obj,flag2,type);
					}
				}else{
					$obj.addClass("on").removeClass("bdOn");
					$obj.siblings(".poiTrue").hide();
					$obj.siblings(".poiFalse").css("width","60px");
					$obj.siblings(".poiFalse").text("含有非法词").show();
					$obj.siblings(".regPointIcon").removeClass("regTrue").show();
					return false;
				}
			}
		}

	function checkAccuout($obj,flag2,type){
		var username = jQuery.trim($obj.val());
		if(!flag2.test(username)||(username.length>20||username.length<4) ){	
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").css("width","276px");
			$obj.siblings(".poiFalse").text("用户名4-20位，字母、数字、-、_组成，非数字开头").show();
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else{
			var result = checkAccountExist($obj,type);
			return result;
		}
	}

	function checkEamil($obj,flag1,type){
		var username = jQuery.trim($obj.val());
		if(username.length>50||username.length<4){
			$obj.addClass("on").removeClass("bdOn");
				$obj.siblings(".poiTrue").hide();
				$obj.siblings(".poiFalse").css("width","auto");
				$obj.siblings(".poiFalse").text("邮箱地址长度应在4-50个字符之间").show();
				$obj.siblings(".regPointIcon").removeClass("regTrue").show();
				return false;
		}else if(!flag1.test(username)){
				$obj.addClass("on").removeClass("bdOn");
				$obj.siblings(".poiTrue").hide();
				$obj.siblings(".poiFalse").css("width","auto");
				$obj.siblings(".poiFalse").text("请输入正确的邮箱").show();
				$obj.siblings(".regPointIcon").removeClass("regTrue").show();
				return false;
		}else{
			return checkAccountExist($obj,type);
		}
	}

	function checkAccountExist($obj,type){
		if(type==1){
			return true;
		}else{
			//ajax验证
	    	jQuery.ajax({	
	    		type:'get',
	        	url:domain_passprot+'/newcheck_uname.htm',
	        	data:{param:jQuery.trim($obj.val())},
	        	dataType:'json',
	        	cache:false,
	        	success:function(data){
	    			if(data!=null&&data.status=='n'){
						var info = data.info;
						$obj.addClass("on").removeClass("bdOn");
						$obj.siblings(".poiTrue").hide();
						$obj.siblings(".poiFalse").css("width","auto");
						$obj.siblings(".poiFalse").text(info).show();
						$obj.siblings(".regPointIcon").removeClass("regTrue").show();
						return false;
	    			}else{
	    				$obj.removeClass("on").removeClass("bdOn");
						$obj.siblings(".poiTrue").hide();
						$obj.siblings(".poiFalse").hide();
						$obj.siblings(".regPointIcon").addClass("regTrue").show();
						return true;
	    			}
	    		}
	    	});
		}
	}
	//验证用户名结束

	//验证密码
	
	function checkPwd($obj){
		var regexp=/(\w|\d)/;
		var regexp1=/^\d+$/g;
		var regexp2=/^[a-zA-Z]+$/g;
		var regexp3=/^[\;!,@#$%^&*?_~`(){}\[\]\-\+:"'|\\<>\/\.=]+$/g;
		//var regexp4=/(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*?]+)$)^[\w~!@#$%\^&*?]+$/;
		var password = $obj.val();
		var username = jQuery.trim($('#eUsername').val());
		if(password==''){
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("请输入密码").show();
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			$obj.siblings(".tip").show();
			return false;
		}else if(password.length<8||password.length>20){
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("密码长度为8-20位").show();
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else if(regexp1.test(password)||regexp2.test(password)||regexp3.test(password)){
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("数字、字母、符号至少包含两种").show();;
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else if(username==password){
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("密码和用户名不能相同").show();;
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else {
			$obj.removeClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").hide();
			$obj.siblings(".regPointIcon").addClass("regTrue").show(); 
			return true;
		}
	}
	//验证密码结束

	//验证再次输入的密码开始
	function checkRePwd($obj,$pwd){
		var $this = $obj;
		var repassword = $this.val();
		var password = $pwd.val();
		if(repassword==''){
			$this.addClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").text("请再次输入密码").show();
			$this.siblings(".regPointIcon").removeClass("regTrue").show();
			$obj.siblings(".tip").show();
			return false;
		}else if(password!=repassword){
			$this.addClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").text("两次输入密码不一致").show();
			$this.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else{
			$this.removeClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").hide();
			$this.siblings(".regPointIcon").addClass("regTrue").show(); 
			return true;
		}
	}
	
	//验证再次输入的密码结束
	
	//验证验证码开始
	function checkCode($obj){
		var $this = $obj;
		if(jQuery.trim($this.val())==''){
			$this.addClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").show();
			$this.siblings(".regPointIcon").removeClass("regTrue").show();
			$obj.siblings(".tip").show();
			return false;
		}else{
			$this.removeClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").hide(); 
			return true;
		}
	}


	function checkCode1($obj){
		var $this = $obj;
		if(jQuery.trim($this.val())==''){
			$this.parent().removeClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").show();
			$this.siblings(".regPoint").text("请输入验证码");
			$this.siblings(".regPointIcon").removeClass("regTrue").show();
			$obj.siblings(".tip").show();
			return false;
		}else{
			$this.parent().removeClass("on").removeClass("bdOn");
			$this.siblings(".poiTrue").hide();
			$this.siblings(".poiFalse").hide();
			$this.siblings(".regPointIcon").addClass("regTrue").show(); 
			return true;
		}
	}
	//验证验证码结束

	//验证手机号
	function checkPhone($obj){
		var value = jQuery.trim($obj.val());
		var pattern=/^(13|14|15|18|17)[0-9]{9}$/;
		if(value==''){
			$obj.addClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("请输入手机号").show();
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			$obj.siblings(".tip").show();
			return false;
		}else if(!pattern.test(value)){
			$obj.addClass("on").removeClass("bdOn");	
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").text("请输入正确的手机号码").show();
			$obj.siblings(".regPointIcon").removeClass("regTrue").show();
			return false;
		}else{
			$obj.removeClass("on").removeClass("bdOn");
			$obj.siblings(".poiTrue").hide();
			$obj.siblings(".poiFalse").hide();
			$obj.siblings(".regPointIcon").addClass("regTrue").show();
			return true;
		}
	}
	//验证手机号结束

	//注册成功
	
	$(".regSucBtn").bind('click',function(){
		$(".loginBox,.popMask").hide();
		window.location.href = "http://cart.jiuxian.com";
	});
	
	function CookieEnable(){
		var result= false ;
		if (navigator.cookiesEnabled) return true ;
		document.cookie = "testcookie=yes;" ;
		var cookieSet = document.cookie;
		if (cookieSet.indexOf( "testcookie=yes" ) > -1) result= true ;
		document.cookie = "" ;
		return result;
	}
	
	if (!CookieEnable()){
		alert( "对不起，您的浏览器的Cookie功能被禁用，请开启后刷新重试" );
	}
	
})
